//
//  GFJnViewController.m
//  Qyer
//
//  Created by dlios on 15/10/19.
//  Copyright (c) 2015年 GF. All rights reserved.
//

#import "GFJnViewController.h"

@interface GFJnViewController ()<UIScrollViewDelegate, GFButtonScrollViewDelegate, GFTbViewDelegate, GFCollectviewDelegate>
@property (nonatomic, strong)GFButtonScrollView *buttonView;
@property (nonatomic, strong)NSArray *idArray;
@property (nonatomic, strong)UIView *lineView;
@property (nonatomic, strong)NSString *afnString;
@property (nonatomic, strong)UIScrollView *scView;
@end

@implementation GFJnViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _idArray = @[@"https://chanyouji.com/api/trips/featured.json?page=1", @"https://chanyouji.com/api/destinations.json"];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selector(goBack)];
    
    [self setAutomaticallyAdjustsScrollViewInsets:NO];
    
    _scView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 114 * HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - 162 * HEIGHT)];
    [_scView setBounces:NO];
    [_scView setPagingEnabled:YES];
    [_scView setShowsHorizontalScrollIndicator:NO];
    [_scView setContentOffset:CGPointMake(0, 0) animated:YES];
    [_scView setContentSize:CGSizeMake(SCREEN_WIDTH * 2, 0)];
    [_scView setDelegate:self];
    
    GFTbView *tbVeiw = [[GFTbView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 162 * HEIGHT)];
    [tbVeiw setTbDelegate:self];
    [_scView addSubview:tbVeiw];
    
    GFCollectView *jnView = [[GFCollectView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 162 * HEIGHT)];
    [jnView setCDelegate:self];
    [_scView addSubview:jnView];
    
    [self.view addSubview:_scView];
    _buttonView = [[GFButtonScrollView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 50 * HEIGHT)];
    [_buttonView setButtonDelegate:self];
    [self.view addSubview:_buttonView];
    _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 48 * HEIGHT, SCREEN_WIDTH / 2, 2 * HEIGHT)];
    [_lineView setBackgroundColor:[UIColor blueColor]];
    [_buttonView addSubview:_lineView];
}
#pragma mark-滚动按钮点击代理方法实现
- (void)setAInteger:(NSInteger)integer{
    if (integer == 0) {
        [_lineView setFrame:CGRectMake(0, 48 * HEIGHT, SCREEN_WIDTH / 2, 2 * HEIGHT)];
    }else{
        [_lineView setFrame:CGRectMake(SCREEN_WIDTH / 2, 48 * HEIGHT, SCREEN_WIDTH / 2, 2 * HEIGHT)];
    }
    [_scView setContentOffset:CGPointMake(integer * SCREEN_WIDTH, 0) animated:YES];
}

#pragma mark-点击翻页按钮代理方法(封装的tableView的点击方法)
- (void)getAfnString:(NSString *)afnString imageString:(NSString *)imageString dictionary:(NSDictionary *)dictionary{
    GFYjDetailViewController *yj = [[GFYjDetailViewController alloc] init];
    yj.afnString = afnString;
    yj.bigIamge = imageString;
    yj.userDic = dictionary;
    [self.navigationController pushViewController:yj animated:YES];
}

#pragma mark-collectionView继承父类ScrollView代理方法实现
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
        NSInteger temp = (NSInteger)(_scView.contentOffset.x / SCREEN_WIDTH);
    if (scrollView == _scView) {
        switch (temp) {
            case 0:
            {
                [_lineView setFrame:CGRectMake(0, 48 * HEIGHT, SCREEN_WIDTH / 2, 2 * HEIGHT)];
            }
                break;
            case 1:
            {
                [_lineView setFrame:CGRectMake(SCREEN_WIDTH / 2, 48 * HEIGHT, SCREEN_WIDTH / 2, 2 * HEIGHT)];
            }
                break;
            default:
                break;
        }
    }
}
- (void)goBack{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)getTbModel:(GFTbModel *)model{
//    NSString *preString = @"http://chanyouji.com/api/trips/";
//    NSString *hasString = @".json";
//    NSString *comString = [NSString stringWithFormat:@"%@%@%@", preString, model.cId, hasString];
}

- (void)getGFJnModel:(GFJnModel *)model{
    NSString *preString = @"http://chanyouji.com/api/destinations/";
    NSString *hasString = @".json";
    NSString *comString = [NSString stringWithFormat:@"%@%@%@", preString, model.cId, hasString];
    GFGlViewController *gl = [[GFGlViewController alloc] init];
    gl.glString = comString;
    gl.lcId = model.cId;
    [self.navigationController pushViewController:gl animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
